// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OrderChangeEditScrPanel.java

package com.boci.clientapp.orderstatus;

import com.boci.clientapp.main.ApplicationService;
import com.boci.clientapp.main.ClientAppLoader;
import com.boci.clientapp.orderstatus.action.OrderChangeAction;
import com.boci.clientapp.orderstatus.vo.OrderStatusDetailVO;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.ui.AbstractPanel;
import com.boci.common.ui.control.LimitDocument;
import com.boci.common.util.*;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.*;
import javax.swing.*;

public class OrderChangeEditScrPanel extends AbstractPanel
{

    public OrderChangeEditScrPanel(Locale pLocale, String pModuleName, String pScreenName)
    {
        super(pLocale, pScreenName, pScreenName);
        msgConf = ClientAppLoader.getMessagesConfigurator();
        initGUI();
        setText(pLocale);
    }

    public void setText(Locale pLocale)
    {
        super.setText(pLocale);
        setFont(pLocale);
        currentLocale = pLocale;
        lblReference.setText(msgConf.getUIMessages("ORDER_STATUS.REFERENCE_NO", pLocale));
        lblPalceOn.setText(msgConf.getUIMessages("ORDER_STATUS.PLACED_ON", pLocale));
        lblDuration.setText(msgConf.getUIMessages("ORDER_STATUS.DURATION", pLocale));
        lblOrderType.setText(msgConf.getUIMessages("ORDER_STATUS.ORDER_TYPE", pLocale));
        lblPrice.setText(msgConf.getUIMessages("ORDER_STATUS.PRICE", pLocale));
        lblQuantity.setText(msgConf.getUIMessages("ORDER_STATUS.QUANTITY", pLocale));
        lblTransaction.setText(msgConf.getUIMessages("ORDER_STATUS.TRANSACTION", pLocale));
        lblSecurityCode.setText(msgConf.getUIMessages("ORDER_STATUS.CODE", pLocale));
        lblNameOfSecurity.setText(msgConf.getUIMessages("ORDER_STATUS.NAME", pLocale));
        lbltitle.setText(msgConf.getUIMessages("ORDER_STATUS.CHANGE_ORDER", pLocale));
        lblEnterChangesBelow.setText(msgConf.getUIMessages("ORDER_STATUS.ENTER_CHANGES_BELOW", pLocale));
        lblNewQuantity.setText(msgConf.getUIMessages("ORDER_STATUS.ENTER_NEW_QUANTITY", pLocale));
        lblNewPrice.setText(msgConf.getUIMessages("ORDER_STATUS.ENTER_NEW_PRICE", pLocale));
        btnClearChange.setText(msgConf.getUIMessages("ORDER_STATUS.CLEAR_CHANGE", pLocale));
        btnReview.setText(msgConf.getUIMessages("ORDER_STATUS.REVIEW", pLocale));
        btnBack.setText(msgConf.getUIMessages("ORDER_STATUS.BACK_TO_ORDER_STATUS", pLocale));
        if(orderStatusDetailVO != null)
            refresh(orderStatusDetailVO);
    }

    private void setFont(Locale pLocale)
    {
        lbltitle.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblReference.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPalceOn.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblDuration.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblOrderType.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPrice.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblQuantity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblTransaction.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblSecurityCode.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNameOfSecurity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblReferenceValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblPlaceOnValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblDurationValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblOrderTypeValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblPriceValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblQualityValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblTransactionValue.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblSecurityCodeValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblNameOfSecurityValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblEnterChangesBelow.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNewQuantity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNewPrice.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        txtNewQuantity.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        txtNewPrice.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        btnClearChange.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        btnReview.setFont(ClientAppLoader.getBoldButtonFont(pLocale));
        btnBack.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
    }

    public void initGUI()
    {
        setPreferredSize(new Dimension(710, 210));
        setBackground(Color.WHITE);
        setLayout(null);
        lblReferenceValue = new JLabel();
        lblReferenceValue.setBounds(145, 174, 160, 20);
        add(lblReferenceValue);
        lblReference = new JLabel();
        lblReference.setHorizontalAlignment(4);
        lblReference.setBounds(10, 174, 120, 20);
        add(lblReference);
        lblPalceOn = new JLabel();
        lblPalceOn.setHorizontalAlignment(4);
        lblPalceOn.setBounds(10, 155, 120, 20);
        add(lblPalceOn);
        lblPlaceOnValue = new JLabel();
        lblPlaceOnValue.setBounds(145, 155, 160, 20);
        add(lblPlaceOnValue);
        lblDurationValue = new JLabel();
        lblDurationValue.setBounds(145, 136, 160, 20);
        add(lblDurationValue);
        lblDuration = new JLabel();
        lblDuration.setHorizontalAlignment(4);
        lblDuration.setBounds(10, 136, 120, 20);
        add(lblDuration);
        lblOrderType = new JLabel();
        lblOrderType.setHorizontalAlignment(4);
        lblOrderType.setBounds(10, 117, 120, 20);
        add(lblOrderType);
        lblOrderTypeValue = new JLabel();
        lblOrderTypeValue.setBounds(145, 117, 160, 20);
        add(lblOrderTypeValue);
        lblPriceValue = new JLabel();
        lblPriceValue.setBounds(145, 98, 160, 20);
        add(lblPriceValue);
        lblPrice = new JLabel();
        lblPrice.setHorizontalAlignment(4);
        lblPrice.setBounds(10, 98, 120, 20);
        add(lblPrice);
        lblQuantity = new JLabel();
        lblQuantity.setHorizontalAlignment(4);
        lblQuantity.setBounds(10, 79, 120, 20);
        add(lblQuantity);
        lblQualityValue = new JLabel();
        lblQualityValue.setBounds(145, 79, 160, 20);
        add(lblQualityValue);
        lblTransactionValue = new JLabel();
        lblTransactionValue.setForeground(Color.BLUE);
        lblTransactionValue.setBounds(145, 60, 160, 20);
        add(lblTransactionValue);
        lblTransaction = new JLabel();
        lblTransaction.setHorizontalAlignment(4);
        lblTransaction.setBounds(10, 60, 120, 20);
        add(lblTransaction);
        lblSecurityCode = new JLabel();
        lblSecurityCode.setHorizontalAlignment(4);
        lblSecurityCode.setBounds(10, 41, 120, 20);
        add(lblSecurityCode);
        lblSecurityCodeValue = new JLabel();
        lblSecurityCodeValue.setBounds(145, 41, 160, 20);
        add(lblSecurityCodeValue);
        lblNameOfSecurityValue = new JLabel();
        lblNameOfSecurityValue.setBounds(145, 22, 320, 20);
        add(lblNameOfSecurityValue);
        lblNameOfSecurity = new JLabel();
        lblNameOfSecurity.setHorizontalAlignment(4);
        lblNameOfSecurity.setBounds(10, 22, 120, 20);
        add(lblNameOfSecurity);
        lbltitle = new JLabel();
        lbltitle.setBounds(13, 1, 125, 20);
        add(lbltitle);
        btnBack = new JButton();
        btnBack.setMargin(new Insets(2, 2, 2, 2));
        btnBack.setBounds(300, 150, 130, 25);
        btnBack.setActionCommand("BACK_TO_ORDER_STATUS");
        btnBack.addActionListener(this);
        add(btnBack);
        btnReview = new JButton();
        btnReview.setBounds(447, 150, 120, 25);
        btnReview.setActionCommand("CHANGE_EDIT_REVIEW");
        btnReview.addActionListener(this);
        add(btnReview);
        btnClearChange = new JButton();
        btnClearChange.setBounds(584, 150, 120, 25);
        btnClearChange.setActionCommand("CHANGE_EDIT_CLEAR");
        btnClearChange.addActionListener(this);
        add(btnClearChange);
        txtNewPrice = new JTextField();
        txtNewPrice.setBounds(510, 120, 180, 20);
        txtNewPrice.setDocument(new LimitDocument(18));
        add(txtNewPrice);
        txtNewQuantity = new JTextField();
        txtNewQuantity.setBounds(510, 95, 180, 20);
        txtNewQuantity.setDocument(new LimitDocument(18));
        add(txtNewQuantity);
        lblNewPrice = new JLabel();
        lblNewPrice.setBounds(325, 120, 125, 20);
        add(lblNewPrice);
        lblNewQuantity = new JLabel();
        lblNewQuantity.setBounds(325, 95, 170, 20);
        add(lblNewQuantity);
        lblEnterChangesBelow = new JLabel();
        lblEnterChangesBelow.setBounds(325, 65, 325, 20);
        add(lblEnterChangesBelow);
    }

    public void actionPerformed(ActionEvent e)
    {
        String strActionType = e.getActionCommand();
        if(strActionType.equals("CHANGE_EDIT_CLEAR"))
        {
            if(orderStatusDetailVO != null)
                txtNewQuantity.setText(orderStatusDetailVO.getOutstandingQuantity());
            else
                txtNewQuantity.setText("");
            txtNewPrice.setText("");
            txtNewQuantity.requestFocus();
        } else
        if(validate(strActionType))
        {
            PerformanceLogger.startAppTimer();
            OrderChangeAction orderChangeAction = new OrderChangeAction();
            orderChangeAction.doProcess(getInputValue(strActionType), strActionType);
            PerformanceLogger.stopAppTimer();
            PerformanceLogger.doLog((new StringBuilder()).append(getScreenName()).append(".").append(strActionType).toString());
        }
    }

    public void refresh()
    {
        txtNewPrice.setText("");
        txtNewQuantity.setText("");
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                txtNewQuantity.requestFocus();
            }
        }
);
    }

    public void refresh(HashMap pInHashMap)
    {
        ResponseVO responseVO = (ResponseVO)pInHashMap.get("SELECTED_VO");
        if(responseVO == null)
            return;
        if(responseVO instanceof OrderStatusDetailVO)
            orderStatusDetailVO = (OrderStatusDetailVO)responseVO;
        else
            return;
        String strNewQty = (String)pInHashMap.get("NEW_QTY");
        String strNewPrice = (String)pInHashMap.get("NEW_PRICE");
        if(!isNoPriceOrderType(orderStatusDetailVO.getOrderType()))
            txtNewPrice.setText(strNewPrice);
        refresh(responseVO);
        txtNewQuantity.setText(strNewQty);
    }

    public void refresh(ResponseVO pResponseVO)
    {
        if(pResponseVO == null)
        {
            lblReferenceValue.setText("");
            lblPlaceOnValue.setText("");
            lblDurationValue.setText("");
            lblOrderTypeValue.setText("");
            lblPriceValue.setText("");
            lblQualityValue.setText("");
            lblTransactionValue.setText("");
            lblSecurityCodeValue.setText("");
            lblNameOfSecurityValue.setText("");
            txtNewPrice.setText("");
            txtNewQuantity.setText("");
        } else
        if(pResponseVO instanceof OrderStatusDetailVO)
        {
            orderStatusDetailVO = (OrderStatusDetailVO)pResponseVO;
            lblReferenceValue.setText(StringUtil.getReferenceNo(orderStatusDetailVO.getOrderId()));
            String strPlaceOnDate = orderStatusDetailVO.getPlacementDate();
            strPlaceOnDate = StringUtil.formatLastUpdatedDateTime(orderStatusDetailVO.getPlacementDate());
            strPlaceOnDate = strPlaceOnDate != null ? strPlaceOnDate : "";
            lblPlaceOnValue.setText(strPlaceOnDate);
            lblDurationValue.setText(msgConf.getUIMessages(orderStatusDetailVO.getOrderDuration(), currentLocale));
            lblOrderTypeValue.setText(msgConf.getUIMessages(orderStatusDetailVO.getOrderType(), currentLocale));
            if(isNoPriceOrderType(orderStatusDetailVO.getOrderType()))
            {
                lblPriceValue.setVisible(false);
                txtNewPrice.setEnabled(false);
                txtNewPrice.setBackground(Color.LIGHT_GRAY);
            } else
            {
                lblPriceValue.setVisible(true);
                txtNewPrice.setEnabled(true);
                txtNewPrice.setBackground(Color.WHITE);
            }
            String strCcy = msgConf.getUIMessages(orderStatusDetailVO.getCurrency(), currentLocale);
            String strPrice = StringUtil.formatPriceValue(orderStatusDetailVO.getPrice(), strCcy);
            String strTempQty = orderStatusDetailVO.getOrderQuantity();
            if(strTempQty == null || strTempQty.length() == 0)
                strTempQty = orderStatusDetailVO.getOriginalQuantity();
            String strQty = StringUtil.formatQtyValue(strTempQty);
            lblPriceValue.setText(strPrice);
            lblQualityValue.setText(strQty);
            String strBuyOrSell = orderStatusDetailVO.getBuyOrSell();
            if(strBuyOrSell.equalsIgnoreCase("BUY"))
                lblTransactionValue.setForeground(Color.BLUE);
            else
            if(strBuyOrSell.equalsIgnoreCase("SELL"))
                lblTransactionValue.setForeground(Color.RED);
            lblTransactionValue.setText(msgConf.getUIMessages(strBuyOrSell, currentLocale));
            lblSecurityCodeValue.setText(orderStatusDetailVO.getSymbol());
            if(txtNewQuantity.getText().length() == 0)
                txtNewQuantity.setText(orderStatusDetailVO.getOutstandingQuantity());
            String strNameEng = orderStatusDetailVO.getName();
            String strNameChs = orderStatusDetailVO.getName_chs();
            String strNameChi = orderStatusDetailVO.getName_chi();
            if(currentLocale.equals(ClientAppConst.ZH_HK) && strNameChi != null && strNameChi.length() != 0)
                lblNameOfSecurityValue.setText(strNameChi);
            else
            if(currentLocale.equals(ClientAppConst.ZH_CN) && strNameChs != null && strNameChs.length() != 0)
                lblNameOfSecurityValue.setText(strNameChs);
            else
                lblNameOfSecurityValue.setText(strNameEng);
        }
    }

    public HashMap getInputValue(String pActionType)
    {
        HashMap map = new HashMap();
        map.put("SELECTED_VO", orderStatusDetailVO);
        map.put("NEW_QTY", txtNewQuantity.getText());
        if(isNoPriceOrderType(orderStatusDetailVO.getOrderType()))
            map.put("NEW_PRICE", orderStatusDetailVO.getPrice());
        else
            map.put("NEW_PRICE", txtNewPrice.getText());
        return map;
    }

    private boolean isNoPriceOrderType(String pOrderType)
    {
        boolean returnFlag = false;
        String strNoPriceTypes[] = ClientAppLoader.getNoPriceOrdTypes();
        int i = 0;
        do
        {
            if(i >= strNoPriceTypes.length)
                break;
            if(strNoPriceTypes[i].equals(pOrderType))
            {
                returnFlag = true;
                break;
            }
            i++;
        } while(true);
        return returnFlag;
    }

    public boolean validate(String pActionType)
    {
        if(pActionType.equals("CHANGE_EDIT_REVIEW"))
        {
            msgKeyList = new ArrayList();
            boolean validFlag = true;
            String strNewQty = txtNewQuantity.getText();
            String strNewPrice = txtNewPrice.getText();
            if(strNewQty == null || strNewQty.length() == 0)
            {
                msgKeyList.add("ORDER_STATUS.MISSING_QTY");
                validFlag = false;
            } else
            {
                try
                {
                    Long.parseLong(strNewQty);
                }
                catch(NumberFormatException e)
                {
                    msgKeyList.add("ORDER_STATUS.QTY_NOT_NUMERIC");
                    validFlag = false;
                }
            }
            if(!isNoPriceOrderType(orderStatusDetailVO.getOrderType()))
                if(strNewPrice == null || strNewPrice.length() == 0)
                {
                    msgKeyList.add("ORDER_STATUS.MISSING_PRICE");
                    validFlag = false;
                } else
                {
                    try
                    {
                        Double.parseDouble(strNewPrice);
                        int intDecimalPlace = strNewPrice.indexOf(".");
                        int intNumOfDec = strNewPrice.length() - intDecimalPlace - 1;
                        String strUpperMarketId = orderStatusDetailVO.getMarketId().toUpperCase();
                        int intDecPointLimit = -1;
                        if(strUpperMarketId.equals("HK"))
                            intDecPointLimit = ClientAppLoader.getHKDecimalLimit();
                        else
                        if(strUpperMarketId.equals("US"))
                            intDecPointLimit = ClientAppLoader.getUSDecimalLimit();
                        else
                        if(strUpperMarketId.equals("OPTION"))
                            intDecPointLimit = ClientAppLoader.getHKDecimalLimit();
                        else
                        if(strUpperMarketId.equals("USOPTION"))
                            intDecPointLimit = ClientAppLoader.getUSDecimalLimit();
                        if(intDecPointLimit != -1 && intNumOfDec > intDecPointLimit)
                        {
                            msgKeyList.add("ORDER_STATUS.INVALID_PRICE");
                            validFlag = false;
                        }
                    }
                    catch(NumberFormatException e)
                    {
                        msgKeyList.add("ORDER_STATUS.PRICE_NOT_NUMERIC");
                        validFlag = false;
                    }
                }
            if(!validFlag)
            {
                ApplicationService.getInstance().showWarningDialog(null, msgKeyList);
                return false;
            }
        }
        return true;
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                txtNewQuantity.requestFocus();
            }
        }
);
    }

    private JLabel lblEnterChangesBelow;
    private JLabel lblNewQuantity;
    private JLabel lblNewPrice;
    private JTextField txtNewQuantity;
    private JTextField txtNewPrice;
    private JButton btnClearChange;
    private JButton btnReview;
    private JButton btnBack;
    private JLabel lbltitle;
    private JLabel lblNameOfSecurity;
    private JLabel lblNameOfSecurityValue;
    private JLabel lblSecurityCodeValue;
    private JLabel lblSecurityCode;
    private JLabel lblTransaction;
    private JLabel lblTransactionValue;
    private JLabel lblQualityValue;
    private JLabel lblQuantity;
    private JLabel lblPrice;
    private JLabel lblPriceValue;
    private JLabel lblOrderTypeValue;
    private JLabel lblOrderType;
    private JLabel lblDuration;
    private JLabel lblDurationValue;
    private JLabel lblPlaceOnValue;
    private JLabel lblPalceOn;
    private JLabel lblReference;
    private JLabel lblReferenceValue;
    private Locale currentLocale;
    private MessagesConfigurator msgConf;
    private OrderStatusDetailVO orderStatusDetailVO;
    private ArrayList msgKeyList;

}
